<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Filter Chains - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.filter.filter_chains.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.filter.filter_chains.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.filter.set.html">Standard Filter Classes</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.filter.html">Zend_Filter</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.filter.writing_filters.html">Writing Filters</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.filter.filter_chains" class="section"><div class="info"><h1 class="title">Filter Chains</h1></div>
    

    <p class="para">
        Often multiple filters should be applied to some value in a particular order. For example, a
        login form accepts a username that should be only lowercase, alphabetic characters.
        <span class="classname">Zend_Filter</span> provides a simple method by which filters may be chained
        together. The following code illustrates how to chain together two filters for the submitted
        username:
    </p>

    <pre class="programlisting brush: php">
// Create a filter chain and add filters to the chain
$filterChain = new Zend_Filter();
$filterChain-&gt;addFilter(new Zend_Filter_Alpha())
            -&gt;addFilter(new Zend_Filter_StringToLower());

// Filter the username
$username = $filterChain-&gt;filter($_POST[&#039;username&#039;]);
</pre>


    <p class="para">
        Filters are run in the order they were added to <span class="classname">Zend_Filter</span>. In the
        above example, the username is first removed of any non-alphabetic characters, and then any
        uppercase characters are converted to lowercase.
    </p>

    <p class="para">
        Any object that implements <span class="classname">Zend_Filter_Interface</span> may be used in a
        filter chain.
    </p>

    <div class="section" id="zend.filter.filter_chains.order"><div class="info"><h1 class="title">Changing filter chain order</h1></div>
        

        <p class="para">
            Since 1.10, the <span class="classname">Zend_Filter</span> chain also
            supports altering the chain by prepending or appending filters. For
            example, the next piece of code does exactly the same as the other
            username filter chain example:
        </p>

        <pre class="programlisting brush: php">
// Create a filter chain and add filters to the chain
$filterChain = new Zend_Filter();

// this filter will be appended to the filter chain
$filterChain-&gt;appendFilter(new Zend_Filter_StringToLower());

// this filter will be prepended at the beginning of the filter chain.
$filterChain-&gt;prependFilter(new Zend_Filter_Alpha());

// Filter the username
$username = $filterChain-&gt;filter($_POST[&#039;username&#039;]);
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.filter.set.html">Standard Filter Classes</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.filter.html">Zend_Filter</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.filter.writing_filters.html">Writing Filters</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.filter.html">Zend_Filter</a></li>
  <li><a href="zend.filter.introduction.html">Introduction</a></li>
  <li><a href="zend.filter.set.html">Standard Filter Classes</a></li>
  <li class="active"><a href="zend.filter.filter_chains.html">Filter Chains</a></li>
  <li><a href="zend.filter.writing_filters.html">Writing Filters</a></li>
  <li><a href="zend.filter.input.html">Zend_Filter_Input</a></li>
  <li><a href="zend.filter.inflector.html">Zend_Filter_Inflector</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>